package com.six666.medicaldevicetestingsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six666.medicaldevicetestingsystem.entity.TestOffiers;
import com.six666.medicaldevicetestingsystem.mapper.TestOffiers_Mapper;
import com.six666.medicaldevicetestingsystem.service.TestOffiers_Service;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class TestOffiers_Service_Impl extends ServiceImpl<TestOffiers_Mapper, TestOffiers> implements TestOffiers_Service  {
    @Override
    public Boolean insert_testoffiers(int testid,int accountid){
        QueryWrapper<TestOffiers> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("accountid",accountid);
        queryWrapper.eq("testid",testid);
        long size=count(queryWrapper);
        if(size>0){
            return false;
        }
        else {
            TestOffiers testoffiers = new TestOffiers();
            testoffiers.setTestid(testid);
            testoffiers.setAccountid(accountid);
            return save(testoffiers);
        }
    }
    @Override
    public List<Integer> get_my_compare_plan_id(int account_id){
        QueryWrapper<TestOffiers> queryWrapper=new QueryWrapper<>();
        if(account_id>0){
            queryWrapper.eq("accountid",account_id);
        }
        List<Integer> res_list=new ArrayList<>();
        List<TestOffiers> testoffiers_list=list(queryWrapper);
        for (TestOffiers testOffiers : testoffiers_list) {
            res_list.add(testOffiers.getTestid());
        }
        res_list=res_list.stream().distinct().collect(Collectors.toList());//去除重复的
        return res_list;
    }

    @Override
    public List<Integer> get_account_id_by_test_id(List<Integer> ongoingTestIdList) {
        List<Integer> res=new ArrayList<>();
        for (Integer integer : ongoingTestIdList) {
            QueryWrapper<TestOffiers> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("TestID", integer);
            List<TestOffiers> testoffiers_list = list(queryWrapper);
            for (TestOffiers testOffiers : testoffiers_list) {
                res.add(testOffiers.getAccountid());
            }
        }
        return res;
    }
}
